//
//  NSString+Size.m
//  NekaPrice
//
//  Created by yu on 2018/6/14.
//  Copyright © 2018年 ma c. All rights reserved.
//

#import "NSString+Size.h"

@implementation NSString (Size)

//高度固定,计算(字符串宽度+左右边距)
- (CGFloat)widthWithFixedHeight:(CGFloat)height andEdgeInsets:(UIEdgeInsets)edgeInsets attributes:(NSDictionary *)attributes {
    CGRect rect = [self boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    CGFloat width = rect.size.width;
    return width + edgeInsets.left + edgeInsets.right;
}

//宽度固定,计算(字符串高度+上下边距)
- (CGFloat)heightWithFixedWidth:(CGFloat)width andEdgeInsets:(UIEdgeInsets)edgeInsets attributes:(NSDictionary *)attributes {
    CGRect rect = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    CGFloat height = rect.size.height;
    return height + edgeInsets.top + edgeInsets.bottom;
}



@end
